import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Hashtable;


public class ReadTAtImmi {
	private static String file2Read ="/home/hnikoue/Documents/Sydney/Data/Results/timeAtImmiFittedData.csv"; 
	private static Hashtable<String,TimeStat> timeAtImmiTable;
	public Hashtable<String,TimeStat> getMap(){
		return timeAtImmiTable;
	}
	public void parseFile(){
		File file = new File(file2Read);
		if(file.isFile()){
			BufferedReader buf = null;
			try {
				buf = new BufferedReader(new FileReader(file2Read));
				String sCurrentLine ;
				buf.readLine();//forgo the first line
				while((sCurrentLine = buf.readLine()) != null){
					addEntry2Map(sCurrentLine);
				}
			} catch (IOException e1) {
				e1.printStackTrace();
			}finally{
				try{
					if (buf != null)buf.close();
				} catch (IOException ex) {
					ex.printStackTrace();
				}
				
			}

		}
	}
	
	private void addEntry2Map(String sCurrentLine) {
		String gate;
		double mu,sigma,lowerSupport,upperSupport;
		String[] entryElements = sCurrentLine.split(",");
		gate = entryElements[0];
		mu = Double.parseDouble(entryElements[1]);
		sigma = Double.parseDouble(entryElements[2]);
		lowerSupport = Double.parseDouble(entryElements[3]);
		upperSupport = Double.parseDouble(entryElements[4]);
		TimeStat t2Immi4Flight = new TimeStat(gate,mu,sigma,lowerSupport,upperSupport);
		timeAtImmiTable.put(gate, t2Immi4Flight);
	}
	public ReadTAtImmi(){
		timeAtImmiTable = new Hashtable<String,TimeStat>();
		parseFile();
	}
}
